import { buildUrl, supplyUrl, roadUrl } from "@/config/index"
import disLine10kv from "../geojson/10kVLine.json"
import infoBox from '@/plugins/toolsManage/infoWindow/infoWindow'

const disLine = function(viewer, Cesium) {
    var self = this
    this.viewer = viewer
    this.Cesium = Cesium
    this.infoWindow = new infoBox(viewer)
    this.colorMap = {
        "天顶变": this.Cesium.Color.fromCssColorString('#6da8f9').withAlpha(0.8),
        "望城坡变": this.Cesium.Color.fromCssColorString('#f98e6d').withAlpha(0.8),
        "金谷变": this.Cesium.Color.fromCssColorString('#ff8ab7').withAlpha(0.8),
        "桐梓坡变": this.Cesium.Color.fromCssColorString('#8984ff').withAlpha(0.8),
        "石岭塘变": this.Cesium.Color.fromCssColorString('#03d07a ').withAlpha(0.8),
        "西站变": this.Cesium.Color.fromCssColorString('#c5a74d').withAlpha(0.8)
    }
    this.selectLine = null
}

disLine.prototype = {
    init() {
        let self = this
        disLine10kv.features.forEach(featur => {
                var poins = []
                try {
                    featur.geometry.coordinates.forEach(coor => {
                        coor.push(60)
                        poins = poins.concat(coor)
                    })
                    let posct3 = this.Cesium.Cartesian3.fromDegreesArrayHeights(poins)
                    let lineColor = this.colorMap[featur.properties.GuiShu]
                    var point = {
                        key: "disLine",
                        show: true,
                        polyline: {
                            positions: posct3,
                            width: 2,
                            material: lineColor || this.Cesium.Color.fromCssColorString('#03D07A').withAlpha(0.8),
                        },
                        attr: featur.properties,
                        defaultMaterial: lineColor || this.Cesium.Color.fromCssColorString('#03D07A').withAlpha(0.8),
                        click: function() {
                            var tempPoup = `<div class="infolist"><span >线路名称:${featur.properties.Name}</span></div>`
                            self.infoWindow.show(featur.properties.Name, tempPoup, featur.properties.GuiShu)
                        }
                    }
                    this.viewer.entities.add(point)
                } catch (e) {

                }
            })
            // this.RoadMap = new Map();
            // let self = this
            // var promise = self.Cesium.GeoJsonDataSource.load("/static/geojson/10kVLine.json", { clampToGround: true });
            // promise.then(function(dataSource) {
            //     self.viewer.dataSources.add(dataSource);
            //     var entities = dataSource.entities.values;
            //     for (var i = 0; i < entities.length; i++) {
            //         var entity = entities[i];
            //         // self.RoadMap.set(entity._properties.gml_id._value,entity)
            //         entity.polyline.width = 2
            //         let lineColor = self.colorMap[entity._properties.GuiShu._value]
            //         entity.polyline.material = lineColor || self.Cesium.Color.fromCssColorString('#ccd').withAlpha(1)
            //         // new self.Cesium.PolylineGlowMaterialProperty({
            //         //     glowPower : 0.3,
            //         //      color : lineColor || self.Cesium.Color.BLUE.withAlpha(0.9),
            //         // })
            //     }
            // });
    },

    hide() {

    },
    show(id) {

    },
    goto(id) {

    },
    guid() {
        function S4() {
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        }

        return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    }

}

export default disLine